package com.liuche.homechat.common.user.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liuche.homechat.common.common.exception.BusinessErrorEnum;
import com.liuche.homechat.common.user.domain.entity.User;
import com.liuche.homechat.common.user.mapper.UserMapper;
import com.liuche.homechat.common.user.service.IUserService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author <a href="https://github.com/0liu0">liuche</a>
 * @since 2023-10-29
 */
@Service
public class UserDao extends ServiceImpl<UserMapper, User> implements IUserService {

    /**
     * 根据姓名查找用户
     * @param newName
     * @return
     */
    public User getByName(String newName) {
        return lambdaQuery().eq(User::getName, newName)
                .one();
    }

    /**
     * 修改用户姓名
     * @param uid
     * @param name
     */
    public void modifyName(Long uid, String name) {
        User user = User.builder()
                .id(uid)
                .name(name)
                .build();
        updateById(user);
    }

    /**
     * 更改用户徽章
     * @param uid
     * @param badgeId
     */
    public void wearingBadge(Long uid, Long badgeId) {
        User user = User.builder()
                .id(uid)
                .itemId(badgeId).build();
        updateById(user);    }
}
